// Package value wraps the basic types and provide arithmetic method to operate on add.
package operand

import "fmt"

// Value is the wrapped interface for basic types.
type Value interface {
	Add(other any) (any, error)
	Sub(other any) (any, error)
	Mul(other any) (any, error)
	Div(other any) (any, error)
	Mod(other any) (any, error)
	Neg() (any, error)
	Bool() bool
	Eq(other any) bool
}

// New wrap the value into the specific value types.
func New(value any) (Value, error) {
	switch val := value.(type) {
	case uint:
		return Uint(val), nil
	case uint8:
		return Uint(val), nil
	case uint16:
		return Uint(val), nil
	case uint32:
		return Uint(val), nil
	case uint64:
		return Uint(val), nil
	case int:
		return Int(val), nil
	case int8:
		return Int(val), nil
	case int16:
		return Int(val), nil
	case int32:
		return Int(val), nil
	case int64:
		return Int(val), nil
	case float32:
		return Float(val), nil
	case float64:
		return Float(val), nil
	case fmt.Stringer:
		return Str(val.String()), nil
	case string:
		return Str(val), nil
	case bool:
		return Bool(val), nil
	default:
		return nil, fmt.Errorf("unsupported type: %v", val)
	}
}
